package reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ReflectDemo6 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
        Person p=new Person();
//        p.heiheihei();
        Class cls=Class.forName("reflect.Person");
       Object obj= cls.newInstance();
       Method[] methods=cls.getMethods();
       Method[] methods1=cls.getDeclaredMethods();
       for (Method method:methods1){
           System.out.println(method.getName());
       }
//      Method method= cls.getMethod("heiheihei");
      Method method= cls.getDeclaredMethod("heiheihei");
       method.setAccessible(true);
       method.invoke(obj);
       method.setAccessible(false);

    }
}
